<script setup>
import { onMounted, watch } from 'vue';
import { ref } from 'vue';
import { useRoute } from 'vue-router';

const role = localStorage.getItem('role');
console.log("Home index:"+role);

const route = useRoute();

onMounted(() => {
  setActiveMenu(route.path);
});

const activeMenu = ref('');

const setActiveMenu = (path) => {
  activeMenu.value = path;
};

watch(
  () => route.path,
  (newPath) => {
    setActiveMenu(newPath);
  }
);

</script>

<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <el-menu router mode="horizontal" :default-active="activeMenu" :ellipsis="false">
          <h3 class="sysname">实验室成果管理系统</h3>
          <div class="flex-grow"></div>
          <el-menu-item index="/home/userinfo">个人信息</el-menu-item>
          <el-menu-item v-if="role === 'ROLE_TEACHER'" index="/home/students_mange">学生管理</el-menu-item>
          <el-menu-item v-if="role === 'ROLE_ADMIN'" index="/home/teachers_mange">教师管理</el-menu-item>
          <el-menu-item v-if="role === 'ROLE_STUDENT'" index="/home/achievement">成果管理</el-menu-item>
          <el-menu-item v-if="role === 'ROLE_TEACHER'" index="/home/review">审核管理</el-menu-item>
        </el-menu>
      </el-header>
      <el-main>
        <RouterView></RouterView>
      </el-main>
    </el-container>
  </div>
</template>

<style scoped>
.flex-grow {
  flex-grow: 1;
}

.sysname {
  padding-right: 3px;
}
</style>
